package com.javaclimb.drug.controller;

import com.javaclimb.drug.common.ResultMapUtil;
import com.javaclimb.drug.common.UploadUtils;
import com.javaclimb.drug.entity.UploadInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

/**
 * <p>
 *图片模糊匹配的controller
 * </P>
 *
 * @Author 樊森草
 * @Date 2022-4-2 10:33
 * @fileName
 * @Version 1.0.0.0
 */
@Controller
@RequestMapping(value = "/imgMatch")
public class MatchController {

    /**
     * 跳转到图片模糊查询页面
     * @return
     */
    @RequestMapping
    public String match(){
        return "/imgMatch";
    }

    /**
     * 上传
     * @param file
     * @return
     */
    @RequestMapping(value = "/upload")
    @ResponseBody
    public Object upload(MultipartFile file, HttpServletRequest request){

        
        UploadInfo uploadInfo = UploadUtils.upload(file);
        HashMap<String,String> map = new HashMap<String, String>();
        String src = file.toString();
        System.out.println("本地路径"+src);
        map.put("src",uploadInfo.getFileServerPath());

        map.put("path",uploadInfo.getFileName());
        if(uploadInfo.getFileServerPath() != null){
            return ResultMapUtil.getHashMapUpload(1,map);
        }else {
            return ResultMapUtil.getHashMapUpload(0,map);
        }

    }
    @RequestMapping(value = "/query")
    @ResponseBody
    public Object query(String type){
        //延时
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        HashMap<String,String> map = new HashMap<String, String>();
        map = ResultMapUtil.getImgInfo(type);
        return ResultMapUtil.getHashMapUpload(1,map);

    }
    @RequestMapping(value = "/query1")
    @ResponseBody
    public Object query1(String path){
        //延时
//        try {
//            Thread.sleep(5000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println("查询");
        HashMap<String,String> map = new HashMap<String, String>();
        map = ResultMapUtil.getImgInfo(path);
        return ResultMapUtil.getHashMapUpload(1,map);

    }


}
